#include "head.h"

ControlButton::ControlButton(QWidget *parent)
    :QWidget(parent)
{
    resize(Widget::MAINWIDGET_WIDTH, 120);
    setMinimumSize(Widget::MAINWIDGET_WIDTH, 120);
    setAttribute(Qt::WA_TranslucentBackground, true);
    loadWidget();
//    setStyleSheet("QLabel {background-color: white;}");//设置样式
//        setAutoFillBackground(true);//执行填充
}


void ControlButton::loadWidget()
{
    auto hb = new QHBoxLayout();
//    hb->setSpacing(36);一般来讲，
//只是想控件的间距均分的话，设定好内边距即可然后间距会自动分配（要么设置好setContentsMargins，要么设置setSpacing，两者一起会冲突最后以满足setContentsMargins条件为先）
    hb->setContentsMargins(90, 10, 90, 0);
    setLayout(hb);

    auto labelLeft = new QPushButton();
    labelLeft->resize(ButtonWidth, ButtonHeight);
    labelLeft->setMinimumSize(ButtonWidth, ButtonHeight);
    labelLeft->setIcon(QPixmap(":/images/Resources/previousButton.png"));
    labelLeft->setIconSize(QSize(ButtonWidth, ButtonHeight));
    labelLeft->setFlat(true);
    labelLeft->setStyleSheet("background-color:transparent;");
    hb->addWidget(labelLeft, 0);

    auto playButton = new QPushButton();
    _playButton = playButton;
    playButton->resize(ButtonWidth + 16, ButtonWidth + 16);
    playButton->setMinimumSize(ButtonWidth + 16, ButtonWidth + 16);
    playButton->setIcon(QPixmap(":/images/Resources/playButton.png"));
    playButton->setIconSize(QSize(ButtonWidth + 16, ButtonWidth + 16));
    playButton->setFlat(true);
    playButton->setStyleSheet("background-color:transparent;");
    connect(playButton, SIGNAL(clicked()), this, SLOT(changeStatue()));
    hb->addWidget(playButton, 0);

    auto labelRight = new QPushButton();
    labelRight->resize(ButtonWidth, ButtonHeight);
    labelRight->setMinimumSize(ButtonWidth, ButtonHeight);
    labelRight->setIcon(QPixmap(":/images/Resources/nextButton.png"));
    labelRight->setIconSize(QSize(ButtonWidth, ButtonHeight));
    labelRight->setFlat(true);
    labelRight->setStyleSheet("background-color:transparent;");
    hb->addWidget(labelRight, 0);

}

void ControlButton::acceptResetBegin(){
    if(!_firstLoad)
    {
//        _startPlay = false;
//        emit sendChangeStatueToMusicPlayer(_startPlay);
        return;
    }
    _startPlay = true;
    changeStatue();
}

void ControlButton::changeStatue()
{
    if(!_firstLoad)
    {
        _startPlay = false;
        emit sendChangeStatueToMusicPlayer(_startPlay);
        return;
    }
    if(_startPlay)
    {
        _playButton->setIcon(QPixmap(":/images/Resources/playButton.png"));
        _startPlay = false;
    }else{
        _playButton->setIcon(QPixmap(":/images/Resources/pauseButton.png"));
        _startPlay = true;
    }
    emit sendChangeStatueToMusicPlayer(_startPlay);
}


ControlButton::~ControlButton()
{

}


